﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DTO;
using BUS;

namespace QLVBDQ
{
    /// <summary>
    /// Interaction logic for TimKiemKhachHang.xaml
    /// </summary>
    public partial class TimKiemKhachHang : UserControl
    {
        public TimKiemKhachHang()
        {
            InitializeComponent();
        }

        public void ShowResult(KhachHang_DTO _item)
        {
            
            List<KhachHang_DTO> list = KhachHang_BUS.Instance.TimKiemKhachHang(_item);
            this.listKhachHang.Items.Clear();
            if (list == null)
            {
                MessageBox.Show("Không Tìm Thấy Khách Trong CSDL");
                this.listKhachHang.Items.Clear();
                return;
            }
            for (int i = 0; i < list.Count;i++ )
            {
                list[i].STT = i + 1;
                if (list[i].ThanThiet)
                {
                    list[i].LoaiKhachHang = "Khách Hàng Quen";
                }
                else
                {
                    list[i].LoaiKhachHang = "Khách Vãng Lai";
                }
                this.listKhachHang.Items.Add(list[i]);
            }
            this.listKhachHang.Items.Refresh();

        }

        private void btnTim_Click(object sender, RoutedEventArgs e)
        {
            KhachHang_DTO item = new KhachHang_DTO(this.maKH.Text.ToString(), this.tenKH.Text.ToString(), this.diaChi.Text.ToString(), (bool)this.thanThiet.IsChecked);
            ShowResult(item);
        }
    }
}
